#include <complex>
#include "SSB.hpp"

using namespace std;


void PSS(int NID, int *pss)
{
    int NID2 = NID % 3;
    int x[128] = {0, 1, 1, 0, 1, 1, 1};
    for (int i = 7; i < 128; i++)
    {
        x[i] = (x[i - 3] + x[i - 7]) % 2;
    }
    int q = 43 * NID2;
    for (int i = 0; i < 128; i++)
    {
        pss[i] = 1 - 2 * x[((i + q) % 127)];
    }
}

void SSS(int NID, int *sss)
{
    int x0[128] = {1};
    int x1[128] = {1};
    for (int i = 7; i < 128; i++)
    {
        x0[i] = (x0[i - 3] + x0[i - 7]) % 2;
        x1[i] = (x1[i - 6] + x1[i - 7]) % 2;
    }

    int NID2 = NID % 3;
    int NID1 = (NID - NID2) / 3;
    int m0 = ((int)(NID1 / 112)) * 15 + 5 * NID2;
    int m1 = NID1 % 112;

    for (int i = 0; i < 128; i++)
    {
        sss[i] = (1 - 2 * x0[((i + m0) % 127)]) * (1 - 2 * x1[((i + m1) % 127)]);
    }
}